/*
 * $Id: Box.java 182 2009-06-04 16:30:30Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.apps.pictureviewer.widget;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.border.EmptyBorder;



/**
 * Box.
 * 
 * @author Andreas Meyer
 * @version $Revision: 182 $
 */
public class Box extends AbstractWidget implements FocusListener {

	private static final long serialVersionUID = -8588606866612469905L;


	/**
	 * Construct the box.
	 */
	public Box() {
		
		setOpaque(false);
		setLayout(new GridLayout());
		setBorder(new EmptyBorder(5, 5, 5, 5));
//		setFocusable(true);
//		addFocusListener(this);
	}

	/**
	 * @see deltadesk.apps.pictureviewer.widget.gui.swing.widget.AbstractWidget#paintComponent(java.awt.Graphics2D)
	 */
	@Override
	protected void paintComponent(final Graphics2D g2) {

		final Rectangle rect = g2.getClipBounds();
		
		g2.setPaint(new GradientPaint(0, 1, new Color(225, 227, 203), 0,
				rect.height - 2, new Color(181, 176, 154)));
		g2.fillRoundRect(1, 1, rect.width - 2, rect.height - 2, 6, 6);
		
		if(isFocusOwner()) {
			g2.setColor(Color.BLACK);
			g2.drawRoundRect(1, 1, rect.width - 2, rect.height - 2, 6, 6);
		} // end if
	}

	/**
	 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
	 */
	public void focusGained(final FocusEvent ev) {
		repaint();
	}

	/**
	 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
	 */
	public void focusLost(final FocusEvent ev) {
		repaint();
	}

}
